<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ page session="false"%>
<%@ page pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>媒体列表</title>
<META http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<link href="<c:url value="/resources/css/normalize.css" />" rel="stylesheet" type="text/css" />
<link href="<c:url value="/resources/css/lib.css" />" rel="stylesheet" type="text/css" />
<link href="<c:url value="/resources/css/style.css" />" rel="stylesheet" type="text/css" />

<script src="<c:url value="/resources/jquery/1.6/jquery.js" />"></script>
<script src="<c:url value="/resources/scripts/regionUtil.js" />"></script> 
<script src="<c:url value="/resources/scripts/categoryUtil.js" />"></script>
<script src="<c:url value="/resources/scripts/pager.js" />"></script>
<style>

</style>
</head>
<body>
<input type="hidden" name="regionId" id="regionId" />
<p id="regionSelectorContainer"></p>
<table class="table-style1">
	<thead>
		<tr>
			<th>名称</th>
			<th>所属分类</th>
			<th>所在区域</th>
			<th>价格</th>
			<th>状态</th>
			<th>删除</th>
		</tr>
	</thead>
	<tbody>
	<c:forEach var="p" items="${results.items}">
		<tr>
			<td><a href="<c:url value="/product/update?id=" />${p.id}">${p.name}</a></td>
			<td class="tdCategory">${p.categoryId}</td>
			<td class="tdRegion">${p.regionId}</td>
			<td>${p.price}/${p.unit}</td>
			<td class="tdStatus">${p.status}</td>
			<td>
			<c:if test="${p.status!='delete'}">
				<a href="javascript: void(0);" onclick="confirmDelete(this, ${p.id});">删除</a>
			</c:if>	
			</td>
		</tr>
	</c:forEach>
	</tbody>
</table>
<div id="pager" class="pager f12 mt10 mb10"></div>
</body>
</html>
<script>
	function confirmDelete(el, id){
		var b = confirm('确定要删除吗?');
		if(!b){
			return;
		}
		document.location.href = '<c:url value="/product/delete" />?id=' + id;
	}
	$(document).ready(function() {
		$('.table-style1 td.tdCategory').each(function(td){
			var categoryId = $(this).text();
			$(this).text(CategoryUtil.getPath(categoryId));
		});
		$('.table-style1 td.tdRegion').each(function(td){
			var regionId = $(this).text();
			$(this).text(RegionUtil.getPath(regionId));
		});
		
		$('.table-style1 td.tdStatus').each(function(td){
			var status = $(this).text();
			if(status=='delete'){
				$(this).text('已删除');
			}
			else{
				$(this).text('正常');
			}
			
		});
        var pager = new Pager(${results.page}, 10, 3, ${results.total}, '#pager', '<c:url value="/product/list" />');
        pager.createPagerBar('#pager');
        
        
    });
</script>
